package com.web.hilover.service.impl;

import com.web.hilover.entity.Couple;
import com.web.hilover.mapper.CoupleMapper;
import com.web.hilover.service.CoupleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class CoupleServiceImpl implements CoupleService {
    
    @Autowired
    private CoupleMapper coupleMapper;
    
    @Override
    public List<Couple> getTopCouples(int limit) {
        return coupleMapper.findTopByLikes(limit);
    }
    
    @Override
    public List<Couple> getRandomCouples(int limit) {
        return coupleMapper.findRandom(limit);
    }
    
    @Override
    public List<Couple> getCouplesByYear(int year) {
        List<Couple> couples = coupleMapper.findByYear(year);
        log.info("Fetched couples for year {}: {}", year, couples);
        return couples;
    }
    
    @Override
    public Couple getCoupleById(Long id) {
        return coupleMapper.findById(id);
    }
    
    @Override
    public void addCouple(Couple couple) {
        coupleMapper.insert(couple);
    }
    
    @Override
    public void updateCouple(Couple couple) {
        coupleMapper.update(couple);
    }
    
    @Override
    public void deleteCouple(Long id) {
        coupleMapper.deleteById(id);
    }
    
    @Override
    public List<Couple> searchCouples(String keyword) {
        return coupleMapper.search(keyword);
    }
    
    @Override
    public List<Map<String, Object>> getAllCouplesWithDetail() {
        return coupleMapper.findAllWithDetail();
    }
    
    @Override
    public List<Couple> getAllPublicCouples() {
        List<Couple> couples = coupleMapper.findAllPublic();
        log.info("Fetched couples: {}", couples);
        return couples;
    }
    
    @Override
    public List<Couple> getCouplesByUser(Long userId) {
        return coupleMapper.findByUser(userId);
    }
} 